package com.gagakuai.engine.impl.interceptor.defaultImpl;

import com.gagakuai.engine.impl.interceptor.Command;
import com.gagakuai.engine.impl.interceptor.CommandConfig;

/*
 * @program: common-starters
 * @description: 日志拦截器:开启日志记录
 * @author: houhong
 * @create: 2023-01-01 23:13
 */
public class LogInterceptor extends AbstractCommandInterceptor {


    @Override
    public <T> T execute(CommandConfig config, Command<T> command) {

        if (!logger.isDebugEnabled()) {
            return getNext().execute(config, command);
        }

        logger.debug("\n");
        logger.debug("--- starting {} --------------------------------------------------------", command.getClass().getSimpleName());

        try {
            return getNext().execute(config, command);
        } finally {
            //在执行链执行完毕后 会回来 执行这里
            logger.debug("--- finished {} --------------------------------------------------------", command.getClass().getSimpleName());
        }

    }
}